package com.shou.infrastructure.persistent.repository.fee.mapstruct;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shou.domain.fee.model.FeeScheduleEntity;
import com.shou.infrastructure.persistent.po.FeeSchedulePO;
import org.mapstruct.Mapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName:FeeSchedulePOConvert
 * Project:SmartPark
 * Package: com.shou.infrastructure.persistent.repository.fee.mapstruct
 * Description
 *
 * @Author Nemo
 * @Create 2025/2/7 23:15
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface FeeSchedulePOConvert {

    FeeSchedulePO convertFeeScheduleEntityToPO(FeeScheduleEntity feeScheduleEntity);
    FeeScheduleEntity convertFeeSchedulePOToEntity(FeeSchedulePO feeSchedulePO);

    // 批量转换，会依据单体转换的规则进行转换
    List<FeeSchedulePO> convertFeeScheduleEntityToPOList(List<FeeScheduleEntity> feeScheduleEntityList);
    List<FeeScheduleEntity> convertFeeSchedulePOToEntityList(List<FeeSchedulePO> feeSchedulePOList);
    default IPage<FeeScheduleEntity> convertFeeSchedulePOPageToEntity(IPage<FeeSchedulePO> pageMessage){
        if (pageMessage == null || pageMessage.getRecords() == null || pageMessage.getRecords().isEmpty()) {
            return null;
        }
        List<FeeScheduleEntity> pageMessageEntities = pageMessage.getRecords().stream()
                .map(this::convertFeeSchedulePOToEntity)
                .collect(Collectors.toList());

        IPage<FeeScheduleEntity> entityPage = new Page<>();
        entityPage.setRecords(pageMessageEntities);
        entityPage.setTotal(pageMessage.getTotal());
        entityPage.setSize(pageMessage.getSize());
        entityPage.setCurrent(pageMessage.getCurrent());
        return entityPage;
    }
}
